// 导入路由表
import routes from "./config";
// 创建路由组件
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
import NotFound from "../views/Error/NotFound";
// 创建404组件

const Router = () => {
  return (
    <BrowserRouter>
      <Routes>
        {routes.map((item) => {
          return (
            <Route
              key={item.path}
              //   访问路径
              path={item.path}
              //   显示组件
              element={
                // 如果有对应的组件
                item.element ? (
                  <item.element />
                ) : item.redirect ? (
                  <Navigate to={item.redirect} />
                ) : (
                  <Navigate to="/404" />
                )
              }
            />
          );
        })}
        <Route path="*" element={<NotFound />}></Route>
      </Routes>
    </BrowserRouter>
  );
};
export default Router;
